package com.tonghl.juc.container_study.code;

import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;

/**
 * Created by tonghl
 *
 * Map中安全的 ConcurrentHashMap
 *            Collections.synchronizedMap();
 */
public class ContainerNoSafeDemo2 {

    public static void main(String[] args) {

        // HashMap<Object, Object> map = new HashMap<>();
        Map<String, String> map= new ConcurrentHashMap<>();
        for (int i = 1; i <=30 ; i++)
        {
            new Thread(()->
            {
                map.put(Thread.currentThread().getName(),UUID.randomUUID().toString().substring(0,8));
                System.out.println(map);
            },String.valueOf(i)).start();
        }
    }
}
